/**
 * <copyright>
 * </copyright>
 *
 */
package lco.cRLanguage.impl;

import java.util.Collection;

import lco.cRLanguage.AssignmentRightHand;
import lco.cRLanguage.CRLanguagePackage;
import lco.cRLanguage.ForJava;
import lco.cRLanguage.NumericFunctionExpression;
import lco.cRLanguage.Statement;
import lco.cRLanguage.Variable;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>For Java</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getInitialization <em>Initialization</em>}</li>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getAssignment <em>Assignment</em>}</li>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getCondition <em>Condition</em>}</li>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getComparison <em>Comparison</em>}</li>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getExpression <em>Expression</em>}</li>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getVariable <em>Variable</em>}</li>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getOperation <em>Operation</em>}</li>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getStep <em>Step</em>}</li>
 *   <li>{@link lco.cRLanguage.impl.ForJavaImpl#getStatements <em>Statements</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ForJavaImpl extends MinimalEObjectImpl.Container implements ForJava
{
  /**
   * The cached value of the '{@link #getInitialization() <em>Initialization</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getInitialization()
   * @generated
   * @ordered
   */
  protected Variable initialization;

  /**
   * The cached value of the '{@link #getAssignment() <em>Assignment</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getAssignment()
   * @generated
   * @ordered
   */
  protected AssignmentRightHand assignment;

  /**
   * The cached value of the '{@link #getCondition() <em>Condition</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getCondition()
   * @generated
   * @ordered
   */
  protected Variable condition;

  /**
   * The default value of the '{@link #getComparison() <em>Comparison</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getComparison()
   * @generated
   * @ordered
   */
  protected static final String COMPARISON_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getComparison() <em>Comparison</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getComparison()
   * @generated
   * @ordered
   */
  protected String comparison = COMPARISON_EDEFAULT;

  /**
   * The cached value of the '{@link #getExpression() <em>Expression</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getExpression()
   * @generated
   * @ordered
   */
  protected NumericFunctionExpression expression;

  /**
   * The cached value of the '{@link #getVariable() <em>Variable</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getVariable()
   * @generated
   * @ordered
   */
  protected Variable variable;

  /**
   * The default value of the '{@link #getOperation() <em>Operation</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getOperation()
   * @generated
   * @ordered
   */
  protected static final String OPERATION_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getOperation() <em>Operation</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getOperation()
   * @generated
   * @ordered
   */
  protected String operation = OPERATION_EDEFAULT;

  /**
   * The default value of the '{@link #getStep() <em>Step</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStep()
   * @generated
   * @ordered
   */
  protected static final int STEP_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getStep() <em>Step</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStep()
   * @generated
   * @ordered
   */
  protected int step = STEP_EDEFAULT;

  /**
   * The cached value of the '{@link #getStatements() <em>Statements</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStatements()
   * @generated
   * @ordered
   */
  protected EList<Statement> statements;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ForJavaImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return CRLanguagePackage.Literals.FOR_JAVA;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Variable getInitialization()
  {
    if (initialization != null && initialization.eIsProxy())
    {
      InternalEObject oldInitialization = (InternalEObject)initialization;
      initialization = (Variable)eResolveProxy(oldInitialization);
      if (initialization != oldInitialization)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRLanguagePackage.FOR_JAVA__INITIALIZATION, oldInitialization, initialization));
      }
    }
    return initialization;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Variable basicGetInitialization()
  {
    return initialization;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setInitialization(Variable newInitialization)
  {
    Variable oldInitialization = initialization;
    initialization = newInitialization;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__INITIALIZATION, oldInitialization, initialization));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public AssignmentRightHand getAssignment()
  {
    return assignment;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetAssignment(AssignmentRightHand newAssignment, NotificationChain msgs)
  {
    AssignmentRightHand oldAssignment = assignment;
    assignment = newAssignment;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__ASSIGNMENT, oldAssignment, newAssignment);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setAssignment(AssignmentRightHand newAssignment)
  {
    if (newAssignment != assignment)
    {
      NotificationChain msgs = null;
      if (assignment != null)
        msgs = ((InternalEObject)assignment).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CRLanguagePackage.FOR_JAVA__ASSIGNMENT, null, msgs);
      if (newAssignment != null)
        msgs = ((InternalEObject)newAssignment).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CRLanguagePackage.FOR_JAVA__ASSIGNMENT, null, msgs);
      msgs = basicSetAssignment(newAssignment, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__ASSIGNMENT, newAssignment, newAssignment));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Variable getCondition()
  {
    if (condition != null && condition.eIsProxy())
    {
      InternalEObject oldCondition = (InternalEObject)condition;
      condition = (Variable)eResolveProxy(oldCondition);
      if (condition != oldCondition)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRLanguagePackage.FOR_JAVA__CONDITION, oldCondition, condition));
      }
    }
    return condition;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Variable basicGetCondition()
  {
    return condition;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setCondition(Variable newCondition)
  {
    Variable oldCondition = condition;
    condition = newCondition;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__CONDITION, oldCondition, condition));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getComparison()
  {
    return comparison;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setComparison(String newComparison)
  {
    String oldComparison = comparison;
    comparison = newComparison;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__COMPARISON, oldComparison, comparison));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NumericFunctionExpression getExpression()
  {
    return expression;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetExpression(NumericFunctionExpression newExpression, NotificationChain msgs)
  {
    NumericFunctionExpression oldExpression = expression;
    expression = newExpression;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__EXPRESSION, oldExpression, newExpression);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setExpression(NumericFunctionExpression newExpression)
  {
    if (newExpression != expression)
    {
      NotificationChain msgs = null;
      if (expression != null)
        msgs = ((InternalEObject)expression).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CRLanguagePackage.FOR_JAVA__EXPRESSION, null, msgs);
      if (newExpression != null)
        msgs = ((InternalEObject)newExpression).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CRLanguagePackage.FOR_JAVA__EXPRESSION, null, msgs);
      msgs = basicSetExpression(newExpression, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__EXPRESSION, newExpression, newExpression));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Variable getVariable()
  {
    if (variable != null && variable.eIsProxy())
    {
      InternalEObject oldVariable = (InternalEObject)variable;
      variable = (Variable)eResolveProxy(oldVariable);
      if (variable != oldVariable)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, CRLanguagePackage.FOR_JAVA__VARIABLE, oldVariable, variable));
      }
    }
    return variable;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Variable basicGetVariable()
  {
    return variable;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setVariable(Variable newVariable)
  {
    Variable oldVariable = variable;
    variable = newVariable;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__VARIABLE, oldVariable, variable));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getOperation()
  {
    return operation;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setOperation(String newOperation)
  {
    String oldOperation = operation;
    operation = newOperation;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__OPERATION, oldOperation, operation));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getStep()
  {
    return step;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setStep(int newStep)
  {
    int oldStep = step;
    step = newStep;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, CRLanguagePackage.FOR_JAVA__STEP, oldStep, step));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Statement> getStatements()
  {
    if (statements == null)
    {
      statements = new EObjectContainmentEList<Statement>(Statement.class, this, CRLanguagePackage.FOR_JAVA__STATEMENTS);
    }
    return statements;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case CRLanguagePackage.FOR_JAVA__ASSIGNMENT:
        return basicSetAssignment(null, msgs);
      case CRLanguagePackage.FOR_JAVA__EXPRESSION:
        return basicSetExpression(null, msgs);
      case CRLanguagePackage.FOR_JAVA__STATEMENTS:
        return ((InternalEList<?>)getStatements()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case CRLanguagePackage.FOR_JAVA__INITIALIZATION:
        if (resolve) return getInitialization();
        return basicGetInitialization();
      case CRLanguagePackage.FOR_JAVA__ASSIGNMENT:
        return getAssignment();
      case CRLanguagePackage.FOR_JAVA__CONDITION:
        if (resolve) return getCondition();
        return basicGetCondition();
      case CRLanguagePackage.FOR_JAVA__COMPARISON:
        return getComparison();
      case CRLanguagePackage.FOR_JAVA__EXPRESSION:
        return getExpression();
      case CRLanguagePackage.FOR_JAVA__VARIABLE:
        if (resolve) return getVariable();
        return basicGetVariable();
      case CRLanguagePackage.FOR_JAVA__OPERATION:
        return getOperation();
      case CRLanguagePackage.FOR_JAVA__STEP:
        return getStep();
      case CRLanguagePackage.FOR_JAVA__STATEMENTS:
        return getStatements();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case CRLanguagePackage.FOR_JAVA__INITIALIZATION:
        setInitialization((Variable)newValue);
        return;
      case CRLanguagePackage.FOR_JAVA__ASSIGNMENT:
        setAssignment((AssignmentRightHand)newValue);
        return;
      case CRLanguagePackage.FOR_JAVA__CONDITION:
        setCondition((Variable)newValue);
        return;
      case CRLanguagePackage.FOR_JAVA__COMPARISON:
        setComparison((String)newValue);
        return;
      case CRLanguagePackage.FOR_JAVA__EXPRESSION:
        setExpression((NumericFunctionExpression)newValue);
        return;
      case CRLanguagePackage.FOR_JAVA__VARIABLE:
        setVariable((Variable)newValue);
        return;
      case CRLanguagePackage.FOR_JAVA__OPERATION:
        setOperation((String)newValue);
        return;
      case CRLanguagePackage.FOR_JAVA__STEP:
        setStep((Integer)newValue);
        return;
      case CRLanguagePackage.FOR_JAVA__STATEMENTS:
        getStatements().clear();
        getStatements().addAll((Collection<? extends Statement>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case CRLanguagePackage.FOR_JAVA__INITIALIZATION:
        setInitialization((Variable)null);
        return;
      case CRLanguagePackage.FOR_JAVA__ASSIGNMENT:
        setAssignment((AssignmentRightHand)null);
        return;
      case CRLanguagePackage.FOR_JAVA__CONDITION:
        setCondition((Variable)null);
        return;
      case CRLanguagePackage.FOR_JAVA__COMPARISON:
        setComparison(COMPARISON_EDEFAULT);
        return;
      case CRLanguagePackage.FOR_JAVA__EXPRESSION:
        setExpression((NumericFunctionExpression)null);
        return;
      case CRLanguagePackage.FOR_JAVA__VARIABLE:
        setVariable((Variable)null);
        return;
      case CRLanguagePackage.FOR_JAVA__OPERATION:
        setOperation(OPERATION_EDEFAULT);
        return;
      case CRLanguagePackage.FOR_JAVA__STEP:
        setStep(STEP_EDEFAULT);
        return;
      case CRLanguagePackage.FOR_JAVA__STATEMENTS:
        getStatements().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case CRLanguagePackage.FOR_JAVA__INITIALIZATION:
        return initialization != null;
      case CRLanguagePackage.FOR_JAVA__ASSIGNMENT:
        return assignment != null;
      case CRLanguagePackage.FOR_JAVA__CONDITION:
        return condition != null;
      case CRLanguagePackage.FOR_JAVA__COMPARISON:
        return COMPARISON_EDEFAULT == null ? comparison != null : !COMPARISON_EDEFAULT.equals(comparison);
      case CRLanguagePackage.FOR_JAVA__EXPRESSION:
        return expression != null;
      case CRLanguagePackage.FOR_JAVA__VARIABLE:
        return variable != null;
      case CRLanguagePackage.FOR_JAVA__OPERATION:
        return OPERATION_EDEFAULT == null ? operation != null : !OPERATION_EDEFAULT.equals(operation);
      case CRLanguagePackage.FOR_JAVA__STEP:
        return step != STEP_EDEFAULT;
      case CRLanguagePackage.FOR_JAVA__STATEMENTS:
        return statements != null && !statements.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (comparison: ");
    result.append(comparison);
    result.append(", operation: ");
    result.append(operation);
    result.append(", step: ");
    result.append(step);
    result.append(')');
    return result.toString();
  }

} //ForJavaImpl
